
public class Point2D implements Comparable {

	private double x;
	private double y;
	
	
	public Point2D(double x, double y){
		setX(x);
		setY(y);
	}
	
	public double getDistance(Point2D p){
		double afstand = Math.sqrt(Math.pow(this.getX() - p.getX(), 2) + Math.pow(this.getY() - p.getY(), 2));
		return afstand;
	}

	public double getX() {
		return x;
	}
	
	public double getY() {
		return y;
	}
	
	public void setX(double x) {
		this.x = x;
	}
	
	public void setY(double y) {
		this.y = y;
	}
	
	public boolean equals(Point2D p){
		return(this.getX() == p.getX() && this.getY() == p.getY());
	}
	
	public int compareTo(Object x){
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		Point2D point = (Point2D) x;
		
		if (point.getX() > this.getX())
			return BEFORE;
		else if (point.getX() < this.getX())
			return AFTER;
		else
			return EQUAL;
	}

}
